//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Rodaja.h"

void Rodaja::crearRodaja(){
        float inc = 2*M_PI/lados;
        for (int i=0;i<lados;i++){
                vertices[i] = new PV3D((float)radio*cos(2*M_PI-i*inc),(float)radio*sin(2*M_PI-i*inc),0,1);
        }
};

void Rodaja::dibuja(){ 
        if (vertices == NULL || lados == 0) return;
        glBegin(GL_POLYGON);
        for(int i=0;i<lados;i++){
                float x = vertices[i]->getX();
                float y = vertices[i]->getY();
                float z = vertices[i]->getZ();
                glVertex3f(x,y,z);
        }
        glEnd();
};

void Rodaja::setVertices(PV3D** v){
        if(vertices == NULL) vertices = new PV3D*[lados];
        for (int i=0;i<lados;i++){
                if(vertices[i] != NULL){
                        delete vertices[i];
                        vertices[i] = NULL;
                }
                vertices[i] = v[i]->clona();
        }
};

Rodaja* Rodaja::clona(){
        Rodaja* r = new Rodaja(radio,lados);
        PV3D** v = new PV3D*[lados];
        for(int i=0;i<lados;i++){
                v[i] = vertices[i]->clona();
        }
        r->setVertices(v);
        return r;
};

//---------------------------------------------------------------------------

#pragma package(smart_init)
 